package org.benjamin.lending.controller;


import com.fasterxml.jackson.databind.ObjectMapper;
import org.benjamin.lending.domain.Menu;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;
import java.io.IOException;
import java.util.List;

@Controller
public class HomeController {

    @RequestMapping(value = "index")
    public String index(){
        return "home.index";
    }

    @ResponseBody
    @RequestMapping(value = "menuJson")
    public List<Menu> menuJson() throws IOException {
        ClassPathResource classPathResource = new ClassPathResource("inputData.json");
        File file = classPathResource.getFile();
        List<Menu> menuList = new ObjectMapper().readValue(file,List.class);
        return menuList;
    }
}
